/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.storage.impl.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 *
 * @author dmitriy
 */
public class Bimap<T> extends HashMap<T, T> {

    public Bimap() {
    }

    @Override
    public boolean containsValue(Object value) {
        return super.containsKey((T) value);
    }

    @Override
    public Set<Entry<T, T>> entrySet() {
        throw new UnsupportedOperationException("Not supported yet");
    }

    @Override
    public Set<T> keySet() {
        throw new UnsupportedOperationException("Not supported yet");
    }

    @Override
    public T put(T key, T value) {
        if (containsKey(key) || containsKey(value))
            throw new IllegalArgumentException("Duplicate entries are not allowed");
        super.put(key, value);
        super.put(value, key);
        return null;
    }

    @Override
    public T remove(Object key) {
        super.remove((T) get((T) key));
        return (T) super.remove((T)key);
    }

    @Override
    public int size() {
        return super.size()/2;
    }

}
